package com.zhl.test;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;

import com.zhl.dao.UserDao;
import com.zhl.model.User;
@Controller
public class UserController {
	 /**
     * @param args
     */
	
    public static void main(String[] args) {
        ApplicationContext ctx=null;
        ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
 
        UserDao userDao=(UserDao) ctx.getBean("userDao");
        User user=new User();
        
        
        //添加两条数据
       
        user.setUsername("老王");
        user.setPassword("123");
        userDao.addUser(user);

        user.setUsername("薛定谔");
        user.setPassword("123");
        userDao.addUser(user);
        
        System.out.println("添加成功");
        
        //查询数据
        user.setId(3);
       // user.setPassword("123");
        System.out.println(userDao.getUser(user).toString());
        
        user.setId(4);
        System.out.println(userDao.getUser(user).toString());
        
        //修改数据
        user.setId(2);
        user.setPassword("802");
        userDao.updateUser(user);
        System.out.println("修改成功");
        
        //查看所有
        List users = userDao.getAllUser();
        for(int i = 0 ; i < users.size(); i++){
        	
        	System.out.println(users.get(i).toString());
        }
        
        
        //删除数据
        userDao.deleteUser("薛定谔");
        System.out.println("删除成功");
        
        //查看所有
        users = userDao.getAllUser();
        for(int i = 0 ; i < users.size(); i++){
        	
        	System.out.println(users.get(i).toString());
        }
        
    }
}
